package com.itheima.filter.service.impl;



import com.itheima.filter.service.inter.DeptService;
import com.itheima.mapper.DpetMapper;
import com.itheima.project.Dept;

import com.itheima.pojo.ProjectUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 业务逻辑层：处理具体的业务逻辑
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Resource//依赖注入
    private DpetMapper deptDao; //= new DpetDaoImpl();


    @Override
    public List<Dept> list() throws IOException {
        //1. 调用deptDao
        List<Dept> lines = deptDao.list();
        return lines;
    }

    @Override
    public void delectDeptById(Integer id) {
        deptDao.delete(id);
    }

    @Override
    public void addDept(Dept dept) {


        ProjectUtil.checkSpace(dept);
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptDao.addDept(dept);


    }

    @Override
    public Dept getInfo(Integer id) {
        Dept dept = deptDao.getDeptById(id);
        return dept;
    }

    @Override
    public void modifyDept(Dept dept) {
            ProjectUtil.checkSpace(dept);
            dept.setUpdateTime(LocalDateTime.now());
            deptDao.modifyDept(dept);

    }

}
